Gitlab Raw API Tool
Easily call any GitLab REST API, customize requests, and filter response fields for debugging or advanced workflows. Streamline integration with GitLab for efficient project and task management.
Instructions
支持自定义调用任意 GitLab REST API,适合调试和高级用法。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | No | 请求体 | |
| endpoint | Yes | GitLab API 路径,如 /projects | |
| fields | No | 需要返回的字段路径数组,支持数组或逗号分隔字符串,用于过滤 API 响应字段。 示例: - ["id", "name", "owner.username"] - "id,name,owner.username" - undefined | |
| method | Yes | HTTP 方法 | |
| params | No | 查询参数 |
Implementation Reference
- src/tools/GitlabRawApiTool.ts:17-56 (handler)The execute function implementing the core logic of the Gitlab Raw API Tool: validates args, creates GitLab client, performs API request, optionally filters response fields, and returns JSON or error.async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) { const typedArgs = args as { endpoint: string; method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; params?: Record<string, any>; data?: Record<string, any>; fields?: string[]; }; try { const client = createGitlabClientFromContext(context); const response = await client.apiRequest( typedArgs.endpoint, typedArgs.method, typedArgs.params, typedArgs.data ); if (typedArgs.fields) { const filteredResponse = filterResponseFields(response, typedArgs.fields); return { content: [{ type: "text", text: JSON.stringify(filteredResponse) }] } as ContentResult; } return { content: [{ type: "text", text: JSON.stringify(response) }] } as ContentResult; } catch (error: any) { return { content: [ { type: "text", text: `GitLab MCP 工具调用异常:${error?.message || String(error)}` } ], isError: true }; } }
- src/tools/GitlabRawApiTool.ts:10-16 (schema)Zod schema defining the input parameters for the tool: endpoint (API path), method (HTTP method), optional params, data, and fields for response filtering.parameters: z.object({ endpoint: z.string().describe("GitLab API 路径,如 /projects"), method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).describe("HTTP 方法"), params: z.record(z.any()).optional().describe("查询参数"), data: z.record(z.any()).optional().describe("请求体"), fields: createFieldsSchema(), }),
- src/gitlab-tools-sdk.ts:71-80 (registration)Array defining all GitLab tools for FastMCP registration, including GitlabRawApiTool.const fastmcpTools = [ GitlabAcceptMRTool, GitlabCreateMRCommentTool, GitlabCreateMRTool, GitlabGetUserTasksTool, GitlabRawApiTool, GitlabSearchProjectDetailsTool, GitlabSearchUserProjectsTool, GitlabUpdateMRTool, ];
- src/gitlab-tools-sdk.ts:142-147 (registration)Core registration loop in registerGitLabToolsForFastMCP that adds GitlabRawApiTool (and others) to the FastMCP server using server.addTool(tool).fastmcpTools.forEach(tool => { const standardizedName = toolNameMapping[tool.name as keyof typeof toolNameMapping]; if (shouldRegisterTool(standardizedName as GitLabToolName, options.toolFilter)) { // GitLabTool is now fully compatible with FastMCP's base type, can be registered directly server.addTool(tool); }
- src/gitlab-tools-sdk.ts:65-65 (registration)Name mapping for GitlabRawApiTool to its standardized registered name 'Gitlab_Raw_API_Tool' used in filtering and typing.[GitlabRawApiTool.name]: "Gitlab_Raw_API_Tool",